#include "mainwindow.h"

#include <QApplication>
#include <QFile>
#include <QDir>

#include <QtWebSockets/QWebSocket>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWebSocket socket;
    socket.open(QUrl("ws://localhost:1234")); // WebSocket服务器的URL

       QString filePath = QDir::homePath() + "/" + "test.txt"; // 要发送的文件路径
       QFile file(filePath);
       if (file.open(QIODevice::ReadOnly)) {
           QByteArray fileData = file.readAll();
           socket.sendBinaryMessage(fileData); // 发送文件数据
           file.close();

           qDebug() << "successed to open file.";

       } else {
           qDebug() << "Failed to open file.";
       }

       // 等待文件发送完成
       //socket.waitForBytesWritten();
//       socket.close();

    MainWindow w;
    w.show();
    return a.exec();
}
